package com.lcc.control;

import com.lcc.pojo.Tuser;
import com.lcc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 廖聪聪
 * @version 1.0
 * 创建时间 2020/7/24 13:44
 */
@Controller
@RequestMapping("/user")
public class UserControl {
	@Autowired
	private UserService userService;
	/**
	 * 登录操作
	 * @param tuser
	 * @param session
	 * @return
	 */
	@RequestMapping(value = "findUser")
	public void findByUser(Tuser tuser, HttpSession session, HttpServletResponse response) throws IOException {
		String mess="";
		Tuser byUser = userService.findByUser(tuser);
		if (byUser!=null){
			mess="{\"flag\":true}";
			session.setAttribute("user",byUser);
			session.setAttribute("userid",byUser.getUserid());
		}else {
			mess="{\"flag\":false}";
		}

		PrintWriter pw = response.getWriter();
		pw.write(mess);
		pw.flush();
		pw.close();
	}

	@RequestMapping(value = "login")
	public String gologin(){
		return "login";
	}
}
